package com.yykj.tencent.im.server.service.impl;

import com.yykj.tencent.im.server.bean.request.DeleteRecentContactRequest;
import com.yykj.tencent.im.server.bean.request.GetRecentContactListRequest;
import com.yykj.tencent.im.server.bean.response.DeleteRecentContactResult;
import com.yykj.tencent.im.server.bean.response.GetRecentContactListResult;
import com.yykj.tencent.im.server.bean.response.PortraitSetResult;
import com.yykj.tencent.im.server.core.TimUtil;
import com.yykj.tencent.im.server.service.RecentContactService;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class RecentContactServiceImpl implements RecentContactService {
    /**
     * 版本
     */
    private final String Version = "v4";

    /**
     * 最近联系人服务名
     */
    private static final String SERVICE_NAME = "recentcontact";

    /**
     * 最近联系人相关命令字
     */
    private static final String GET_RECENT_CONTACT_LIST = "get_list";
    private static final String DELETE_RECENT_CONTACT = "delete";

    /**
     * 请求接口
     */
    private final String api_url = "%s/%s/%s";


    /**
     * 拉取会话列表
     */
    @SneakyThrows
    @Override
    public GetRecentContactListResult recentContactList(GetRecentContactListRequest recentContactListRequest) {
        String api = String.format(api_url, Version, SERVICE_NAME,GET_RECENT_CONTACT_LIST);
        return TimUtil.post(api,recentContactListRequest, GetRecentContactListResult.class);
    }

    /**
     * 删除单个会话
     */
    @SneakyThrows
    @Override
    public DeleteRecentContactResult deleteRecentContact(DeleteRecentContactRequest deleteRecentContactRequest) {
        String api = String.format(api_url, Version, SERVICE_NAME,DELETE_RECENT_CONTACT);
        return TimUtil.post(api,deleteRecentContactRequest, DeleteRecentContactResult.class);
    }


}
